#include <QApplication>
#include <qDebug>
#include "widget.h"
#include "loggermanager.h"



void testLog() {
    qDebug() << "调试信息（会被重定向）";
    qDebug() << "hello world!";
    qInfo() <<"日志系统正常运行";
    qInfo()<<"the log system is OK";
    qWarning() << "警告信息";
    qWarning() << "This is a Warning";
    qCritical()<< "出现错误";
    qCritical()<< "the Error is now";
    //qFatal()<<"程序异常Keill";
}


void initLogger()
{
    auto lm = LoggerManager::instance();

    lm->initConsoleAppender("console",LogLevel::Debug);//初始化命令行
    // lm->initFileAppender("./logs","app","file",LogLevel::Info);//初始化文件

    // lm->initUdpAppender("10.0.4.208",8888,"udp",LogLevel::Error);//初始化UDP
    // lm->initTcpAppender("10.0.4.208",9999,"tcp",LogLevel::Error);//初始化TCP


    // lm->initQPlainTextEditAppender(w.getPlainTextEdit(),"qPlainTextEdit",LogLevel::Debug);//初始化QPlainTextEdit
    // lm->initQTextEditAppender(w.getTextEdit(),"qTextEdit",LogLevel::Debug);//初始化QTextEdit

    lm->setAllEnable(true);//使能所有输出对象
    lm->startLogSystem();//输出重定向

    qDebug()<<"The log system is starting to record";
}


int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

    Widget w;
    w.show();

    initLogger();
    testLog();

    auto lm = LoggerManager::instance();
    lm->initQPlainTextEditAppender(w.getPlainTextEdit());//初始化QPlainTextEdit
    lm->initQTextEditAppender(w.getTextEdit());//初始化QTextEdit
    lm->setEnable(AppenderType::QPlainTextEdit,true);
    lm->setEnable(AppenderType::QTextEdit,true);

    return a.exec();
}
